package net.sf.jabref.logic.l10n;

import java.nio.file.Path;

class LocalizationEntry implements Comparable<LocalizationEntry>{

    private final Path path;
    private final String key;
    private final LocalizationBundle bundle;

    LocalizationEntry(Path path, String key, LocalizationBundle bundle) {
        this.path = path;
        this.key = key;
        this.bundle = bundle;
    }

    public Path getPath() {
        return path;
    }

    public String getKey() {
        return key;
    }

    public String getId() {
        return String.format("%s___%s", bundle, key);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LocalizationEntry that = (LocalizationEntry) o;

        if (key != null ? !key.equals(that.key) : that.key != null) return false;
        return bundle == that.bundle;

    }

    @Override
    public int hashCode() {
        int result = key != null ? key.hashCode() : 0;
        result = 31 * result + (bundle != null ? bundle.hashCode() : 0);
        return result;
    }

    public LocalizationBundle getBundle() {
        return bundle;
    }

    public String toString() {
        return String.format("%s %s (%s)", path, key, bundle);
    }

    @Override
    public int compareTo(LocalizationEntry o) {
        return getId().compareTo(o.getId());
    }
}
